export class DataParse {
    constructor(data) {
      this.data = data ? data : "";
    }
  
    DecimalDigit(DecimalDigit) {
      let _data = this.data.toString();
      _data = _data.split(".");
      let decimal = _data[1];
      if (decimal.length - DecimalDigit > 0) {
        decimal = decimal.substr(0, DecimalDigit);
      } else if (decimal.length - DecimalDigit < 0) {
        let diff = DecimalDigit - decimal.length;
        for (let i = 0; i < diff; i++) {
          decimal = decimal + "0";
        }
      }
      _data[1] = decimal;
      console.log(_data[1])
      if (!decimal) {
        this.data = _data[0];
      } else {
        this.data = _data.join(".");
      }
  
      return this;
    }
    ThousandsSeparator(ThousandsSeparator) {
      if (ThousandsSeparator) {
        let _data = this.data.toString();
        _data = _data.split(".");
  
        _data[0] = _data[0].replace(/(\d{3})(?=\d)/g, "$1,");
  
        this.data = _data.join(".");
      }
  
      return this;
    }
    CurrencySymbol(CurrencySymbol) {
      this.data =
        CurrencySymbol +
        this.data.toString().replace(/$/gi, "").replace(/¥/gi, "");
      return this;
    }
    dateTimeFormat(data,fmt){
      var o = {
        "M+": data.getMonth() + 1, // 月份
        "d+": data.getDate(), // 日
        "H+": data.getHours(), // 小时
        "m+": data.getMinutes(), // 分
        "s+": data.getSeconds(), // 秒
        "q+": Math.floor((data.getMonth() + 3) / 3), // 季度
        S: data.getMilliseconds(), // 毫秒
      };
      if (/(y+)/.test(fmt))
        fmt = fmt.replace(
          RegExp.$1,
          (data.getFullYear() + "").substr(4 - RegExp.$1.length)
        );
      for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
          fmt = fmt.replace(
            RegExp.$1,
            RegExp.$1.length == 1
              ? o[k]
              : ("00" + o[k]).substr(("" + o[k]).length)
          );
      return fmt;
    }
    DateTime(format) {      
      this.data = this.dateTimeFormat(this.data,format);
      return this;
    }
  }